<?php

namespace Frieza\Modules\Position\Controllers;

use Biz\model\advertisement\MPositionBaseInfo;
use Biz\service\advertisement\apiModule\BaseModule;
use Doraemon\service\position\PositionConstInterface;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;

/**
 * Class SingleFloatBannerController
 * @package Frieza\Modules\Position\Controllers
 */
class SingleFloatBannerController extends BaseController
{
    use BaseTrait;

    public $base_field_close_type = MPositionBaseInfo::CLOSE_TYPE_ONCE_INIT;


    public function beforeSortForm(Form $form)
    {
        switch ($this->positionId) {
            case PositionConstInterface::HOME_FLOAT:
                $this->gifControl($form);
                break;
        }
    }


    public function beforeLinkForm(Form $form)
    {
        if ($this->positionId == PositionConstInterface::HOME_FLOAT) {
            $form->hidden('base.close_type');
        } else {
            $form->radio('base.close_type', '关闭时效')->options(MPositionBaseInfo::CLOSE_TYPE_MAP);
        }
        if ($this->positionId == PositionConstInterface::NOTE_DETAIL_FLOAT_BANNER) {
            $form->text('base.single_pic_id', '展示note')->help('多个noteid用,隔开;最多存放25个noteid');
        }

        $form->imgUpload('base.pic_id', '悬浮球图');
    }

    public function extendList(Grid $grid)
    {
        $grid->column('pic_url', '图片')->image('', 100);
        if ($this->positionId != PositionConstInterface::HOME_FLOAT) $grid->column('close_type_desc', '关闭时效');
        if ($this->positionId == PositionConstInterface::HOME_FLOAT) $grid->column('play_times', '播放次数')->using(BaseModule::GIF_PLAY_TIMES);
    }

    public function defaultBaseInfo(Request $request): array
    {
        if ($this->positionId == PositionConstInterface::HOME_FLOAT) $this->base_field_close_type = MPositionBaseInfo::CLOSE_TYPE_DAY;
        return parent::defaultBaseInfo($request);
    }
}
